#include "complex.h"
#include <iostream>

complex_n::complex_n(const fraction &re ,const fraction &im)
{
    this->re=new fraction(re.p,re.q);
    this->im=new fraction(im.p,im.q);
}

complex_n::complex_n()
{
this->re=new fraction(0);
this->re=new fraction(0);
}

void complex_n::print()
{
    this->re->print();
    if(this->im->p>0) 
	{	
	std::cout<<"+";
    this->im->print();
    std::cout<<"i";
	}
}

complex_n::~complex_n()
{
	delete re;
	delete im;
}

complex_n complex_n::conjugation()
{
	return complex_n((*re),(*im)*(-1));
}

complex_n complex_n::operator+(complex_n a)
{
	return complex_n(*re+*(a.re),*im+*(a.im));
}

complex_n complex_n::operator-(complex_n a)
{
	return complex_n(*re-*(a.re),*im-*(a.im));
}

complex_n complex_n::operator*(complex_n a)
{
	return complex_n((*re)*(*(a.re))-(*im)*(*(a.im)),(*im)*(*(a.re))+(*re)*(*(a.im)));
}

complex_n complex_n::operator/(complex_n a)
{
	//TODO
}

double complex_n::module()
{
	return fraction(*re**re+*im**im).fr_sqrt();
}
